#!/bin/bash
function Usage() {
    echo "Usage : $0 DyAvg"
}

if [[ $# -lt 1 ]];then
    Usage
    exit 1
fi

# $1 is the dynamic average of the mem occupation

DyAvg=$1

MemValue=(`free -m | head -2 | tail -1 | awk '{printf("%s %s\n", $2, $3)}'`)
MemPerc=`echo "scale=2;${MemValue[1]}*100/${MemValue[0]} " | bc`
NowDyAvg=`echo "scale=2;0.8*${DyAvg}+0.2*${MemPerc}" | bc`

NowTime=`date +"%Y-%m-%d %H:%M:%S"`

echo ${NowTime} ${MemValue[0]}M ${MemValue[1]}M ${MemPerc}% ${NowDyAvg}

